<!-- components/modules/CameraAndTextPanel.vue -->
<template>
  <div class="image-and-text">
    <div class="content-container">
      <!-- 图片区域 -->
      <div class="image-container">
        <div class="camera-image">
          <img :src="cameraImageUrl" alt="摄像头画面" v-if="cameraImageUrl" @click="openModal" />
          <div v-else class="placeholder">图像</div>
        </div>
      </div>

      <!-- 文字区域 -->
      <div class="text-content" v-if="imageUnderstandingResult">
        {{ imageUnderstandingResult }}
      </div>
      <div v-else class="placeholder">文本</div>
    </div>

    <!-- 模态框 -->
    <div v-if="isModalOpen" class="modal-overlay" @click="closeModal">
      <div class="modal-content" @click.stop>
        <img :src="cameraImageUrl" alt="放大后的摄像头画面" class="modal-image" />
        <button class="close-button" @click="closeModal">×</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const props = defineProps({
  cameraImageUrl: {
    type: String,
    default: '',
  },
  imageUnderstandingResult: {
    type: String,
    default: '',
  },
})

const isModalOpen = ref(false)

// 打开模态框
const openModal = () => {
  isModalOpen.value = true
}

// 关闭模态框
const closeModal = () => {
  isModalOpen.value = false
}
</script>

<style scoped>
/* 整体容器 */
.image-and-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* 内容容器 */
.content-container {
  display: flex;
  flex: 1 0 100%;
  flex-direction: column;
  gap: 0px;
}

/* 图片区域 */
.image-container {
  display: flex;
  width:100%;
  flex: 0 0 auto; /* 不随内容伸缩，固定高度 */
  /* width: 480px; */
  height: 70%;
  /* min-height: 400px; */
  justify-content: center;
  align-items: center;
  overflow: hidden;
  border-radius: 0px 0px 0px 0px;
  background-color: #f5f7fa;
  /* border: 1px solid #e0e0e0; */
  padding: 0px;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); /* 添加阴影 */
}

.image-container:hover {
  transform: scale(1.02);
}

.camera-image {
  display: flex;
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  border-radius: 0px 0px 0px 0px;
  background-color: #ffffff;
  /* border: 1px solid #ddd; */
}

.camera-image img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: 0px 0px 0px 0px;
  cursor: pointer;
  /* 移除图片的悬浮效果 */
}

.camera-image .placeholder {
  color: #666;
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* 文字区域 */
.text-content {
  flex: 1;
  overflow-y: auto;
  padding: 6px; /* 增加内边距 */
  font-size: 16px;
  line-height: 1.8; /* 增加行高，提升可读性 */
  color: #2d3748; /* 更深的文字颜色，提升对比度 */
  background-color: #ffffff; /* 纯白背景，更干净 */
  border-radius: 0 0 8px 8px; /* 更大的圆角 */
  border: 1px solid #e2e8f0; /* 更浅的边框颜色 */
  font-family:
    'Inter',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    'Helvetica Neue',
    Arial,
    sans-serif; /* 使用现代字体 */
  animation: fadeIn 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); /* 更柔和的阴影 */

  /* 文字样式优化 */
  font-weight: bold; /* 中等加粗 */
  letter-spacing: 0.05em; /* 轻微字间距，提升阅读体验 */
}

.content-container .placeholder {
  color: #666;
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* 自定义滚动条 */
.text-content::-webkit-scrollbar {
  width: 6px;
}

.text-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.text-content::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 3px;
}

.text-content::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease; /* 保留淡入动画 */
}

.modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  background-color: #ffffff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.modal-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 24px;
  color: #333;
  cursor: pointer;
  transition: color 0.2s ease;
}

.close-button:hover {
  color: #ff4444;
}

/* 动画 */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .content-container {
    flex-direction: column; /* 小屏幕上垂直排列 */
  }
  .image-container,
  .text-content {
    flex: none; /* 取消固定比例 */
    height: auto; /* 自适应高度 */
  }
}
</style>
